import HTMLParser
import urllib
import re


urlString="http://www.ix.pr/members.php"
check=False
urlText=[]
ck=False
class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        if tag=="span":
            check=True
           
                    
    def handle_data(self,data):
        global check
        global ck
        if data!='\n' and check==True:
            if(re.search("^[A][S][N]$",data)):
                ck=True
            elif ck:
                urlText.append(data)
                ck=False
                check=False   
            
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file = open(filePath,"a")
for item in urlText:
    #print item
    print >> file, "76 %s" % item
file.close()